package com.juyu.miliao.common.util;

import com.juyu.miliao.common.constant.HomeVideoTypeConstant;
import com.juyu.miliao.common.domain.dto.HomeVideoCacheKeyDTO;

import static com.juyu.miliao.common.constant.HomeVideoRedis.GLOBAL_NEWEST_KEY;
import static com.juyu.miliao.common.constant.HomeVideoRedis.GLOBAL_RECOMMEND_KEY;
import static com.juyu.miliao.common.constant.HomeVideoRedis.HOT_SORT;
import static com.juyu.miliao.common.constant.HomeVideoRedis.NEWEST_VIDEO_CACHE;
import static com.juyu.miliao.common.constant.HomeVideoRedis.NEW_SORT;
import static com.juyu.miliao.common.constant.HomeVideoRedis.RECOMMEND_VIDEO_CACHE;
import static com.juyu.miliao.common.constant.HomeVideoRedis.VEST_HOT_SORT;
import static com.juyu.miliao.common.constant.HomeVideoRedis.VEST_NEW_SORT;
import static com.juyu.miliao.common.constant.HomeVideoRelationRedis.NEWEST_VIDEO_RANK;
import static com.juyu.miliao.common.constant.HomeVideoRelationRedis.NEWEST_VIDEO_USER;
import static com.juyu.miliao.common.constant.HomeVideoRelationRedis.RECOMMEND_VIDEO_RANK;
import static com.juyu.miliao.common.constant.HomeVideoRelationRedis.RECOMMEND_VIDEO_USER;

/**
 * @author jh
 * 2018/11/15
 */
public class HomeVideoUtil {

    /**
     * 根据条件取到待拼接的首页视频Key,最终的为key + globalKey
     *
     * @param recommend     true-推荐  false-最新
     * @param homeVideoType 视频线上 线下参数
     * @return HomeVideoCacheKeyDTO
     */
    public static HomeVideoCacheKeyDTO getHomeVideoCacheKeyDTO(boolean recommend, String homeVideoType) {
        String jointGlobalKey = (recommend ? GLOBAL_RECOMMEND_KEY : GLOBAL_NEWEST_KEY) + homeVideoType;
        String jointVideoKey = (recommend ? RECOMMEND_VIDEO_CACHE : NEWEST_VIDEO_CACHE) + homeVideoType;
        String jointRankKey = (recommend ? RECOMMEND_VIDEO_RANK : NEWEST_VIDEO_RANK) + homeVideoType;
        String jointUserKey = (recommend ? RECOMMEND_VIDEO_USER : NEWEST_VIDEO_USER) + homeVideoType;
        String sortConstant;

        if (HomeVideoTypeConstant.ON_LINE.equals(homeVideoType)) {
            if (recommend) {
                sortConstant = HOT_SORT;
            } else {
                sortConstant = NEW_SORT;
            }
        } else {
            //线下
            if (recommend) {
                sortConstant = VEST_HOT_SORT;
            } else {
                sortConstant = VEST_NEW_SORT;
            }
        }

        HomeVideoCacheKeyDTO dto = new HomeVideoCacheKeyDTO();
        dto.setJointGlobalKey(jointGlobalKey);
        dto.setJointRankKey(jointRankKey);
        dto.setJointVideoKey(jointVideoKey);
        dto.setJointUserKey(jointUserKey);
        dto.setSortConstant(sortConstant);

        return dto;
    }
}
